home *** CD-ROM | disk | FTP | other *** search
- /*
-
- TRASH SELECTOR
- by Carl W. Haynes III
- Haynes Consulting Services
- PO Box 2715
- W. Lafayette, IN 47906
-
- haynes@mace.cc.purdue.edu
- CWH3@aol.com
-
- Sorry about the no comments/docs, I'm out of time (almost midnight)
-
- Hold down the option key to override my patch when you select
- empty trash from the finders menu
- */
-
-
- #include <SetupA4.h>
-
- #include "Main.h"
-
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- void main()
- {
- Handle self_handle; // a handle to our own code resource */
- Handle show_init;
- Boolean ThereWasAnError;
- int myErr;
- Boolean systemSevenOrLater;
-
- CODE_SETUP(); // push registers to stack, setup A4 */
-
- asm
- {
- _RecoverHandle // A0 already set up
- move.l a0, self_handle //
- }
-
- HLock(self_handle);
-
- DetachResource(self_handle); // so we'll stay after file closed */
-
- init_mac(); // initialize toolbox
-
-
- if(systemSevenOrLater = CheckForSystem7())
- {
- if ((show_init = Get1Resource( 'Code', -4048 )) != 0L)
- {
- HLock( show_init );
- CallPascal( icon_family_ID, *show_init );
- HUnlock( show_init );
- HPurge(show_init);
- }
-
- load_it(); // steal the trap
- }
- else
- {
- if ((show_init = Get1Resource( 'Code', -4048 )) != 0L)
- {
- HLock( show_init );
- CallPascal( DontLoadIcon, *show_init );
- HUnlock( show_init );
- HPurge(show_init);
- }
- }
-
- CODE_CLEANUP(); // restore the registers
- }
-
-
-
-
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- init_mac()
- {
- InitGraf(&our_qd.thePort);
- }
-
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- load_it()
- {
- RememberA4(); /* put a4 contents into CODE segment storage */
-
- itemList = Get1Resource('DITL', 128);
- DetachResource(itemList);
- HNoPurge(itemList);
-
- gMyLDEF = Get1Resource('LDEF', 130);
- DetachResource(gMyLDEF);
- HNoPurge(gMyLDEF);
-
- old_MenuSelect = NGetTrapAddress(MenuSelect_TRAP, ToolTrap);
- NSetTrapAddress((long)our_MenuSelect, MenuSelect_TRAP, ToolTrap);
-
- gOldJGNE = (long)JGNEFilter;
- JGNEFilter = (ProcPtr)myJGNE;
- }
-
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- pascal long our_MenuSelect(Point where)
- {
- long returnValue;
-
- asm {
- movem.l a1-a5/D0-D7, -(SP) ; Save registers
- }
-
- SetUpA4(); // So we can find globals
-
- gOurMenuWasSelected = FALSE;
-
- returnValue = CallPascalL(where, old_MenuSelect);
-
- if ( (HiWord(returnValue) == 261) && (LoWord(returnValue) == 2) )
- {
- if (! KeyIsDown(kScanCodeOption))
- {
- PtoCstr(&CurApName);
- if (strstr(&CurApName, "Finder"))
- {
- gOurMenuWasSelected = TRUE;
- returnValue = 0L;
- }
- CtoPstr(&CurApName);
- }
- }
-
- asm {
- movea.l (A7)+,A4 // RestoreA4();
- movem.l (SP)+, a1-a5/D0-D7 // Restore registers
- }
-
- return(returnValue);
- }
-
- void DoTrashDialog(void)
- {
- Rect wRect;
- Boolean dlgDone;
- DialogPtr theDialog;
- Handle copyOfItemList;
- Ptr dStorage;
- GrafPtr savedPort;
- Rect theRect;
- Handle theItem;
- short theType;
- PenState savedPenState;
- Rect dataBounds;
- Point cellSize = {0, 0};
- short listWidth, listHeight;
- short numOfCellsThatFit;
- Handle savedLDEF;
- Boolean trashSelected = FALSE;
-
- GetPort(&savedPort);
- GetPenState(&savedPenState);
-
- copyOfItemList = itemList;
- HandToHand(©OfItemList);
-
- SetRect(&wRect, 70, 48, 470, 323);
- dStorage = NewPtrSysClear(sizeof(DialogRecord));
-
- theDialog = NewDialog( dStorage, // storage
- &wRect, // wRect
- "\pTrash Selector", // title
- FALSE, // visible
- noGrowDocProc, // wDefProcID
- (DialogPtr)-1L, // behind
- FALSE, // goAwayFlag
- 0L, // refCon
- copyOfItemList); // itemList
- SetPort(theDialog);
-
- GetDItem(theDialog, kListUI, &theType, &theItem, &theRect);
-
- SetRect(&dataBounds, 0, 0, 1, 0);
- gTheList = LNew( &theRect,
- &dataBounds,
- cellSize,
- 0,
- theDialog,
- TRUE,
- FALSE,
- FALSE,
- TRUE);
- if (gTheList == nil)
- {
- DebugStr("\pgTheList == nil");
- return;
- }
- SetWRefCon(theDialog, (long)gTheList);
-
- HLock(gMyLDEF);
- savedLDEF = (**gTheList).listDefProc;
- (**gTheList).listDefProc = gMyLDEF;
- (**gTheList).selFlags = lExtendDrag;
- HLock(gTheList);
-
- listWidth = (**gTheList).rView.right - (**gTheList).rView.left;
- numOfCellsThatFit = ((**gTheList).rView.bottom - (**gTheList).rView.top) / (**gTheList).cellSize.v;
- listHeight = numOfCellsThatFit * (**gTheList).cellSize.v;
- LSize(listWidth, listHeight, gTheList);
-
- gBaseTrashItem = (TrashItemsHdl)NewHandleSysClear(sizeof(TrashItemsRec));
-
- BuildTrashList(gTheList);
- DisplayInitialList(gTheList);
- HUnlock(gTheList);
-
- ShowWindow(theDialog);
-
- dlgDone = FALSE;
- while (dlgDone == FALSE)
- {
- short itemHit;
-
- ModalDialog((ProcPtr)TrashFilter, &itemHit);
-
- switch (itemHit)
- {
- Str255 tempString;
- long totalSelected;
- long endTime;
-
- case kDoUpdate:
-
- BeginUpdate(theDialog);
-
- PenNormal();
-
- DrawDialog(theDialog);
-
- PenSize(1, 1);
- FrameRect(&theDialog->portRect);
- PenNormal();
-
- GetDItem(theDialog, kTrashButton, &theType, &theItem, &theRect);
- InsetRect(&theRect, -4, -4);
- PenSize(3, 3);
- FrameRoundRect(&theRect, 16, 16);
- PenNormal();
-
- GetDItem(theDialog, kTitleBoxUI, &theType, &theItem, &theRect);
- InvertRect(&theRect);
-
- theRect = (**gTheList).rView;
- InsetRect(&theRect, -1, -1);
- FrameRect(&theRect);
-
- HLock(gTheList);
- LUpdate(theDialog->visRgn, gTheList);
- HUnlock(gTheList);
-
- TextFont(applFont);
- TextSize(9);
-
- GetDItem(theDialog, kTotalSelectedUI, &theType, &theItem, &theRect);
- strcpy((Ptr)&tempString, "Total Selected: ");
- TextBox(&tempString, strlen((Ptr)&tempString), &theRect, teJustLeft);
-
- totalSelected = GetTotalSelected(gTheList);
- GetDItem(theDialog, kTotalUnselectedUI, &theType, &theItem, &theRect);
- NumToString(totalSelected, &tempString);
- PtoCstr(&tempString);
- strcat((Ptr)&tempString, "K");
- TextBox(&tempString, strlen((Ptr)&tempString), &theRect, teJustLeft);
-
- TextFont(systemFont);
- TextSize(12);
- PenNormal();
- EndUpdate(theDialog);
- break;
- case kSelectAllButton:
- SelectAll(gTheList);
- GetDItem(theDialog, kTotalUnselectedUI, &theType, &theItem, &theRect);
- InvalRect(&theRect);
- break;
- case kDeselectAllButton:
- DeselectAll(gTheList);
- GetDItem(theDialog, kTotalUnselectedUI, &theType, &theItem, &theRect);
- InvalRect(&theRect);
- break;
- case kTrashButton:
- trashSelected = TRUE;
- dlgDone = TRUE;
- break;
- case kCancelButton:
- dlgDone = TRUE;
- break;
- case kKeyOK:
- GetDItem(theDialog, kTrashButton, &theType, &theItem, &theRect);
- HiliteControl((ControlHandle)theItem, 1);
- Delay(10, &endTime);
- HiliteControl((ControlHandle)theItem, 0);
- trashSelected = TRUE;
- dlgDone = TRUE;
- break;
- case kKeyCancel:
- GetDItem(theDialog, kCancelButton, &theType, &theItem, &theRect);
- HiliteControl((ControlHandle)theItem, 1);
- Delay(10, &endTime);
- HiliteControl((ControlHandle)theItem, 0);
- dlgDone = TRUE;
- break;
- case kDoNothing:
- break;
- default:
- break;
- }
- }
-
- if (trashSelected)
- {
- DeleteSelected(gTheList);
- }
-
- while (gBaseTrashItem != nil)
- {
- TrashItemsHdl tempTrashItems;
-
- tempTrashItems = (**gBaseTrashItem).next;
- DisposHandle(gBaseTrashItem);
- gBaseTrashItem = tempTrashItems;
- }
- gBaseTrashItem = nil;
-
- (**gTheList).listDefProc = savedLDEF;
- HUnlock(gMyLDEF);
-
- LDispose(gTheList);
- gTheList = nil;
-
- HideWindow(theDialog);
- CloseDialog(theDialog);
-
- DisposHandle(copyOfItemList);
- DisposePtr(dStorage);
-
- SetPort(&savedPort);
- SetPenState(&savedPenState);
- }
-
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- pascal Boolean TrashFilter(DialogPtr theDialog, EventRecord *dlgEvent, short *itemHit)
- {
- Rect theRect;
- Handle theItem;
- short theType;
-
- switch ((*dlgEvent).what)
- {
- case updateEvt:
- {
- *itemHit = kDoUpdate;
- return(TRUE);
- }
- case mouseDown:
- {
- Point localPt;
-
- localPt = dlgEvent->where;
- GlobalToLocal(&localPt);
-
- GetDItem(theDialog, kListUI, &theType, &theItem, &theRect);
- theRect.right += 16;
-
- if (PtInRect(localPt, &theRect))
- {
- Cell lastCellClicked;
-
- if (LClick(localPt, dlgEvent->modifiers, gTheList))
- {
- ListEntryRec listEntry;
- short dataLen;
- Cell theCell = {0,0};
-
- SetPt(&theCell, 0, 0);
- if (LGetSelect(TRUE, &theCell, gTheList))
- {
- Str255 tempString;
-
- dataLen = sizeof(ListEntryRec);
- LGetCell(&listEntry, &dataLen, theCell, gTheList);
-
- switch(listEntry.type)
- {
- case kOpenFolderType:
- {
- listEntry.type = kClosedFolderType;
- dataLen = sizeof(ListEntryRec);
- LSetCell(&listEntry, dataLen, theCell, gTheList);
- LDraw(theCell, gTheList);
- break;
- }
- case kClosedFolderType:
- {
- listEntry.type = kOpenFolderType;
- LSetCell(&listEntry, dataLen, theCell, gTheList);
- LDraw(theCell, gTheList);
- break;
- }
- case kFileType:
- {
- break;
- }
- case kApplicationType:
- {
- break;
- }
- default:
- break;
- }
- }
- }
- if (myLClikLoop()){}
- GetDItem(theDialog, kTotalUnselectedUI, &theType, &theItem, &theRect);
- InvalRect(&theRect);
- }
- else
- {
- WindowPtr theWindow;
- Point tempPt;
-
- tempPt = dlgEvent->where;
-
- if (FindWindow(tempPt, &theWindow) == inDrag)
- {
- Rect limitRect;
-
- SetRect(&limitRect, -32000, -32000, 32000, 32000);
- DragWindow(theDialog, tempPt, &limitRect);
- *itemHit = kDoNothing;
- return(TRUE);
- }
- }
-
- return(FALSE);
- }
- case keyDown:
- {
- char theChar;
- Boolean CmdKeyDown;
-
- theChar = (*dlgEvent).message & charCodeMask;
- CmdKeyDown = (((*dlgEvent).modifiers & cmdKey) != 0);
-
- if (CmdKeyDown)
- {
- switch (theChar)
- {
- case kPeriodKey:
- {
- *itemHit = kKeyCancel;
- return(TRUE);
- break;
- }
- default:
- {
- break;
- }
- }
- }
- else
- {
- switch (theChar)
- {
- case kReturnKey:
- case kEnterKey:
- {
- *itemHit = kKeyOK;
- return(TRUE);
- break;
- }
- case kESCKey:
- {
- *itemHit = kKeyCancel;
- return(TRUE);
- break;
- }
- default:
- break;
- }
- }
-
- return(FALSE);
- break;
- }
- default:
- {
- InitCursor();
- return(FALSE);
- }
- }
- }
-
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- void PositionDialog(DialogPtr theDialog)
- {
- Rect tempRect;
- Rect screenRect;
- Rect dialogRect;
- short dialogHeight;
- short dialogWidth;
- short screenHeight;
- short screenWidth;
-
- dialogRect = theDialog->portRect;
- screenRect = screenBits.bounds;
- screenRect.top += GetMBarHeight();
-
- dialogHeight = dialogRect.bottom - dialogRect.top;
- dialogWidth = dialogRect.right - dialogRect.left;
-
- screenHeight = screenRect.bottom - screenRect.top;
- screenWidth = screenRect.right - screenRect.left;
-
- tempRect.left = (screenRect.left + (screenWidth / 2)) - (dialogWidth / 2);
- tempRect.top = (screenRect.top + (screenHeight / 3)) - (dialogHeight / 3);
-
- MoveWindow(theDialog, tempRect.left, tempRect.top, FALSE);
- }
-
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- void BuildTrashList(ListHandle gTheList)
- {
- HFileInfo myCPB;
- short trashVRefNum;
- long trashDirID;
- OSErr myErr;
- OSErr getVInfoErr;
- Ptr namePtr;
- StringPtr PBGetVInfoNamePtr;
- short drvNum = 0;
- Str255 volName;
- short vRefNum;
- long freeBytes;
- Str255 errorStr;
- VolumeParam pb;
-
- pb.ioCompletion = nil;
- pb.ioVolIndex = 1;
- PBGetVInfoNamePtr = (StringPtr)NewPtrSysClear(256);
- pb.ioNamePtr = PBGetVInfoNamePtr;
- pb.ioVRefNum = 0;
-
- while ( (getVInfoErr = PBGetVInfo(&pb, false)) != nsvErr)
- {
- ListEntryRec theListEntry;
- TrashItemsHdl tempTrashItem;
-
- BlockMove(pb.ioNamePtr, &theListEntry.name, pb.ioNamePtr[0] + 1);
- theListEntry.vRefNum = pb.ioVRefNum;
- theListEntry.parID = 0;
- theListEntry.depth = 0;
- theListEntry.type = kDiskType;
- theListEntry.fileSize = 0L;
-
- tempTrashItem = gBaseTrashItem;
- while ((**tempTrashItem).next != nil)
- {
- tempTrashItem = (**tempTrashItem).next;
- }
- HLock(tempTrashItem);
- (**tempTrashItem).next = (TrashItemsHdl)NewHandleSysClear(sizeof(TrashItemsRec));
- HUnlock(tempTrashItem);
-
- tempTrashItem = (**tempTrashItem).next;
- HLock(tempTrashItem);
- BlockMove(&theListEntry, &(**tempTrashItem).listEntry, sizeof(ListEntryRec));
- HUnlock(tempTrashItem);
-
- myErr = FindFolder( pb.ioVRefNum,
- kTrashFolderType,
- FALSE,
- &trashVRefNum,
- &trashDirID);
-
- gDepth = 1;
-
- namePtr = NewPtrSysClear(256);
- gMyCPB.hFileInfo.ioNamePtr = (StringPtr)namePtr;
- gMyCPB.hFileInfo.ioVRefNum = trashVRefNum;
- gCurrentVRefNum = trashVRefNum;
- EnumerateCatalog(trashDirID, gTheList);
-
- DisposPtr(namePtr);
-
- pb.ioVolIndex++;
- pb.ioVRefNum = 0;
- }
-
- DisposPtr(PBGetVInfoNamePtr);
-
- }
-
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
-
- void EnumerateCatalog (long int dirIDToSearch, ListHandle gTheList)
- {
- short int index=1;
- OSErr myErr = noErr;
-
- do
- {
- gMyCPB.hFileInfo.ioFDirIndex = index;
- gMyCPB.hFileInfo.ioDirID = dirIDToSearch; /* we need to do this every time */
- /* through, since GetCatInfo */
- /* returns ioFlNum in this field */
- gMyCPB.hFileInfo.filler2 = 0; /* Clear the ioACUser byte if search is */
- /* interested in it. Nonserver volumes won't */
- /* clear it for you and the value returned is */
- /* meaningless. */
- myErr= PBGetCatInfo(&gMyCPB,false);
- if (myErr == noErr)
- {
- if ((gMyCPB.hFileInfo.ioFlAttrib & ioDirMask) != 0)
- {
- ListEntryRec theListEntry;
- TrashItemsHdl tempTrashItem;
- DirInfo DirInfo;
-
- BlockMove(gMyCPB.dirInfo.ioNamePtr, &theListEntry.name, gMyCPB.dirInfo.ioNamePtr[0] + 1);
- theListEntry.vRefNum = gMyCPB.dirInfo.ioVRefNum;
- theListEntry.parID = gMyCPB.dirInfo.ioDrParID;
- theListEntry.depth = gDepth;
- theListEntry.type = kOpenFolderType;
- theListEntry.fileSize = 0L;
-
- tempTrashItem = gBaseTrashItem;
- while ((**tempTrashItem).next != nil)
- {
- tempTrashItem = (**tempTrashItem).next;
- }
- HLock(tempTrashItem);
- (**tempTrashItem).next = (TrashItemsHdl)NewHandleSysClear(sizeof(TrashItemsRec));
- HUnlock(tempTrashItem);
-
- tempTrashItem = (**tempTrashItem).next;
- HLock(tempTrashItem);
- BlockMove(&theListEntry, &(**tempTrashItem).listEntry, sizeof(ListEntryRec));
- HUnlock(tempTrashItem);
-
- gDepth++;
- EnumerateCatalog(gMyCPB.hFileInfo.ioDirID, gTheList); /* recurse */
- gDepth--;
-
- myErr = noErr; /* clear error return on way back */
- }
- else
- {
- ListEntryRec theListEntry;
- TrashItemsHdl tempTrashItem;
- HFileInfo tempCPB;
-
- BlockMove(gMyCPB.hFileInfo.ioNamePtr, &theListEntry.name, gMyCPB.hFileInfo.ioNamePtr[0] + 1);
- theListEntry.vRefNum = gMyCPB.hFileInfo.ioVRefNum;
- theListEntry.parID = gMyCPB.hFileInfo.ioFlParID;
- theListEntry.depth = gDepth;
- if (gMyCPB.hFileInfo.ioFlFndrInfo.fdType == 'APPL')
- theListEntry.type = kApplicationType;
- else
- theListEntry.type = kFileType;
- theListEntry.fileSize = ((gMyCPB.hFileInfo.ioFlLgLen + gMyCPB.hFileInfo.ioFlRLgLen) / 1024) + 1;
-
- tempTrashItem = gBaseTrashItem;
- while ((**tempTrashItem).next != nil)
- {
- tempTrashItem = (**tempTrashItem).next;
- }
- HLock(tempTrashItem);
- (**tempTrashItem).next = (TrashItemsHdl)NewHandleSysClear(sizeof(TrashItemsRec));
- HUnlock(tempTrashItem);
-
- tempTrashItem = (**tempTrashItem).next;
- HLock(tempTrashItem);
- BlockMove(&theListEntry, &(**tempTrashItem).listEntry, sizeof(ListEntryRec));
- HUnlock(tempTrashItem);
- }
- }
- ++index;
-
- } while (myErr == noErr);
- }
-
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- void DisplayInitialList(ListHandle gTheList)
- {
- TrashItemsHdl tempTrashItem;
- short newRow;
- Cell theCell;
-
- LDelRow(0, 0, gTheList);
-
- tempTrashItem = (**gBaseTrashItem).next;
- while (tempTrashItem != nil)
- {
- HLock(tempTrashItem);
-
- newRow = LAddRow(1, 30000, gTheList);
- SetPt(&theCell, 0, newRow);
- LSetCell(&(**tempTrashItem).listEntry, sizeof(ListEntryRec), theCell, gTheList);
-
- HUnlock(tempTrashItem);
-
- tempTrashItem = (**tempTrashItem).next;
- }
-
- }
-
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- long GetTotalSelected(ListHandle gTheList)
- {
- Cell theCell;
- short totalSize = 0;
-
- SetPt(&theCell, 0, 0);
- while (LGetSelect(TRUE, &theCell, gTheList) == TRUE)
- {
- ListEntryRec listEntry;
- short dataLen;
-
- dataLen = sizeof(ListEntryRec);
- LGetCell(&listEntry, &dataLen, theCell, gTheList);
-
- totalSize += listEntry.fileSize;
-
- LNextCell ( TRUE , TRUE , &theCell, gTheList );
- }
-
- return(totalSize);
- }
-
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- void SelectAll(ListHandle gTheList)
- {
- Cell theCell;
- short count;
- char listState;
-
- listState = HGetState(gTheList);
- HLock(gTheList);
- for (count = 0 ; count <= (**gTheList).dataBounds.bottom - 1 ; count++)
- {
- SetPt(&theCell, 0, count);
- LSetSelect(TRUE, theCell, gTheList);
- }
- HSetState(gTheList, listState);
- }
-
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- void DeselectAll(ListHandle gTheList)
- {
- Cell theCell;
- char listState;
-
- listState = HGetState(gTheList);
- HLock(gTheList);
- SetPt(&theCell, 0, 0);
- while (LGetSelect(TRUE, &theCell, gTheList) == TRUE)
- {
- LSetSelect(FALSE, theCell, gTheList);
- LNextCell (TRUE, TRUE, &theCell, gTheList);
- }
- HSetState(gTheList, listState);
- }
-
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- pascal Boolean myLClikLoop(void)
- {
- Cell theCell;
- char listState;
-
- listState = HGetState(gTheList);
- HLock(gTheList);
-
- SetPt(&theCell, 0, 0);
- while (LGetSelect(TRUE, &theCell, gTheList) == TRUE)
- {
- ListEntryRec listEntry;
- short dataLen;
- Cell nextCell;
- short startingDepth;
- short currentDepth;
-
- dataLen = sizeof(ListEntryRec);
- LGetCell(&listEntry, &dataLen, theCell, gTheList);
-
- if (listEntry.type <= 3 )
- {
- nextCell = theCell;
- startingDepth = listEntry.depth;
- currentDepth = startingDepth;
-
- do {
- ListEntryRec tempListEntry;
- short dataLen;
-
- dataLen = sizeof(ListEntryRec);
- nextCell.v++;
- LGetCell(&tempListEntry, &dataLen, nextCell, gTheList);
- currentDepth = tempListEntry.depth;
- if (currentDepth > startingDepth)
- {
- LSetSelect(TRUE, nextCell, gTheList);
- }
-
- } while( (currentDepth > startingDepth) && (nextCell.v <= (**gTheList).dataBounds.bottom));
- }
-
- LNextCell ( TRUE , TRUE , &theCell, gTheList );
- }
-
- HSetState(gTheList, listState);
- return(TRUE);
- }
-
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- void DeleteSelected(ListHandle gTheList)
- {
- Cell theCell;
- short totalSize = 0;
- short maxDepth = 0;
- short totalToBeSelected = 0;
-
- SetPt(&theCell, 0, 0);
- while (LGetSelect(TRUE, &theCell, gTheList) == TRUE)
- {
- ListEntryRec listEntry;
- short dataLen;
-
- dataLen = sizeof(ListEntryRec);
- LGetCell(&listEntry, &dataLen, theCell, gTheList);
-
- if (listEntry.depth > maxDepth)
- {
- maxDepth = listEntry.depth;
- }
-
- totalToBeSelected++;
-
- LNextCell ( TRUE , TRUE , &theCell, gTheList );
- }
-
- if (maxDepth == 0)
- return;
-
- do {
- SetPt(&theCell, 0, 0);
- while (LGetSelect(TRUE, &theCell, gTheList) == TRUE)
- {
- ListEntryRec listEntry;
- short dataLen;
-
- dataLen = sizeof(ListEntryRec);
- LGetCell(&listEntry, &dataLen, theCell, gTheList);
-
- if (listEntry.depth == maxDepth)
- {
- OSErr myErr;
- HFileParam pb;
- StringPtr theString;
-
- pb.ioCompletion = nil;
- pb.ioVRefNum = listEntry.vRefNum;
- pb.ioDirID = listEntry.parID;
- theString = (StringPtr)NewPtrSysClear(256);
- BlockMove(&listEntry.name, theString, listEntry.name[0] + 1);
- pb.ioNamePtr = theString;
-
- myErr = PBHDelete(&pb, FALSE);
- if (myErr != noErr)
- {
- Str255 errStr;
-
- LSetSelect(FALSE, theCell, gTheList);
- }
- else
- {
- LDelRow(1, theCell.v, gTheList);
- theCell.v--;
-
- myErr = FlushVol(nil, listEntry.vRefNum);
- }
-
- DisposPtr(theString);
- }
-
- LNextCell (FALSE, TRUE, &theCell, gTheList);
- }
- }while (--maxDepth > 0);
-
- }
-
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- //
- // aBoolean = CheckForSystem7() -
- //
- // exit: Boolean = TRUE if we are running system 7 or up
- // FALSE if below system 7
- //
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- Boolean CheckForSystem7(void)
- {
- short myErr;
- long currentSystem;
-
- myErr = Gestalt(gestaltSystemVersion, ¤tSystem);
- if (myErr != noErr)
- {
- return(FALSE);
- }
- else
- {
- if (LoWord(currentSystem) < 0x0700)
- {
- return(FALSE);
- }
- else
- {
- return(TRUE);
- }
- }
- }
-
- //{•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••}
-
- Boolean KeyIsDown(unsigned short key)
- {
- unsigned char theKeyMap[16];
-
- GetKeys (&theKeyMap);
- return ( (theKeyMap[key>>3] >> (key & 7)) & 1);
- }
-
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- static Boolean myGNE (EventRecord *event,Boolean preResult)
- {
- Boolean postResult = preResult;
-
- switch(event->what)
- {
- case nullEvent:
- if (gOurMenuWasSelected == TRUE)
- {
- DoTrashDialog();
- gOurMenuWasSelected = FALSE;
- }
- break;
- default:
- break;
- }
-
- return(postResult);
- }
-
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
-
- static void myJGNE (void) {
- static Boolean inJGNE;
- asm
- {
- MOVE.L A1,A0 ; save event record pointer from __GetA4
- JSR __GetA4 ; point A1 at our A4
- MOVE.L A4,-(A7) ; save old A4
- MOVE.L (A1),A4 ; get new A4
- MOVE.L A0,A1 ; restore old A1
- TST.B inJGNE ; is myJGNE busy?
- BNE @1 ; yes, so bail
- MOVE.B #true,inJGNE ; mark myJGNE busy
- MOVE.W D0,-(A7) ; push pre-result
- MOVE.L A1,-(A7) ; push event record pointer
- JSR myGNE ; do the real work
- MOVE.L (A7)+,A1 ; restore event record pointer
- ADDQ.L #2,A7 ; pop pre-result; post-result in D0
- ASL.W #8,D0 ; bump C boolean to Lisa
- MOVE.W D0,8(A7) ; stash result where caller expects it
- MOVE.B #false,inJGNE ; mark myJGNE not busy
- @1 MOVE.L gOldJGNE,A0 ; get previous jGNE
- MOVE.L (A7)+,A4 ; restore A4
- MOVE.L A0,-(A7) ; return to previous jGNE
- }
- }
-
-
-